//
//  HandDrawingHandler.m
//  dataGathering
//
//  Created by apple on 14/12/22.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "HandDrawingHandler.h"
#import "RectangleMode.h"
#import "SkectchMode.h"
#import "TriangleMode.h"
#import "HandDrawMode.h"
#import "EllipseMode.h"
#import "SingleLineMode.h"

@interface HandDrawingHandler ()
@property(nonatomic, assign)AGSMapView *mapview;
@property(nonatomic, retain)BaseMode *currentMode;

@end

@implementation HandDrawingHandler

-(instancetype)initWithMapView :(AGSMapView*)mapview
{
    self = [super init];
    if(self){
        _mapview = mapview;
    }
    return self;
}

-(void)setMode :(HandDrawingMode)mode type:(NSString*)type
{
    _type = type;
    if([[type uppercaseString] isEqualToString:@"POLYGON"])
    {
        switch (mode) {
            case HandDrawingModePolygon:
                _currentMode = [[SkectchMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeRectangle:
                _currentMode = [[RectangleMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeTriangle:
                _currentMode = [[TriangleMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeEllipse:
                //_currentMode = [[EllipseMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeCircle:
                _currentMode = [[EllipseMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeSkectch:
                _currentMode = [[HandDrawMode alloc] initWithMapview:_mapview];
                break;
                
            default:
                break;
        }
    } else if([[type uppercaseString] isEqualToString:@"POLYLINE"])
    {
        switch (mode) {
            case HandDrawingModeSingleLine:
                _currentMode = [[SingleLineMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeMultiLine:
                _currentMode = [[RectangleMode alloc] initWithMapview:_mapview];
                break;
            case HandDrawingModeLineSketch:
                _currentMode = [[TriangleMode alloc] initWithMapview:_mapview];
                break;
                
            default:
                break;
        }
    } else {
        _currentMode = [[SkectchMode alloc] initWithMapview:_mapview];
    }
    _currentMode.delegate = self;
}

-(void)BaseMode:(BaseMode *)mode didFinishDrawing:(AGSGeometry *)geometry :(NSString *)type
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(HandDrawingHandler:didFinishDrawing::)]) {
        [self.delegate HandDrawingHandler:self didFinishDrawing:geometry :type];
    }
}

-(void)stop
{
    [_currentMode stop];
}

@end
